package com.moleq.models;

import com.moleq.db.DatabaseSchema;
import com.moleq.util.MoleQUtil;

public class PriceSetting {

	private String upc = null; // F01
	private String priceMultiple = null; // F135
	private String price = null; // F136
	private String startdate = null; // F137
	private String starttime = null; // F144
	private String enddate = null; // F138
	private String endtime = null; // F145
	private String packagepricemultiple = null; // F143
	private String packageprice = null; // F139
	private String limitedqtyamount = null; // F147
	private String limitedqtyprice = null; // F148
	private String discountamount = null; // F111
	private String discountpercent = null; // F112
	private String pricemm = null; // F32
	private String createTime = null;// create_datetime
	private String updateTime = null;// update_datetime
	private String dislink = null; // Discount link
	private String price_lvl = null; //price level

	private String retailprice = null;
	private String currentqty = null;

	public int mCurrentPriceQty;
	public double mCurrentPrice;
	public double mDiscountAmount;
	public int mLimitQty;
	public double mLimitPrice;
	public double mRetailPrice;
	public int mRetailQty;
	public double mPackagePrice;
	public int mPackageQty;
	public int mMixMatch;
	public int mDisLink;
	public double mDiscountPercent;
	public int mPriceLvl;

	public boolean isValidDate;
	public boolean isDiscountAmount;
	public boolean isDiscountPercent;
	public boolean isDiscountLink;
	public boolean isMixDiscount;
	public boolean isLimitQty;
	public boolean isCurrentPrice;
	public boolean isPackagePrice;
	public boolean isHaveSetupDate;
	public boolean haveMixAndMatch;
	public boolean isMixAndMatch = false;

	public PriceSetting() {
	}

	public PriceSetting(String _upc, String _priceMultiple, String _price,
			String _startdate, String _starttime, String _enddate,
			String _endtime, String _packagepricemultiple,
			String _packageprice, String _limitedqtyamount,
			String _limitedqtyprice, String _discountamount,
			String _discountpercent, String _pricemm, String _currentqty,
			String _currentprice, String _createTime, String _updateTime,
			String _dislink,String _price_lvl) {

		this.upc = _upc;
		this.priceMultiple = _priceMultiple;
		this.price = _price;
		this.startdate = _startdate;
		this.starttime = _starttime;
		this.enddate = _enddate;
		this.endtime = _endtime;
		this.packagepricemultiple = _packagepricemultiple;
		this.packageprice = _packageprice;
		this.limitedqtyamount = _limitedqtyamount;
		this.limitedqtyprice = _limitedqtyprice;
		this.discountamount = _discountamount;
		this.discountpercent = _discountpercent;
		this.pricemm = _pricemm;
		this.retailprice = _currentprice;
		this.currentqty = _currentqty;
		this.createTime = _createTime;
		this.updateTime = _updateTime;
		this.dislink = _dislink;
		this.price_lvl = _price_lvl;

		long sdatetime, edatetime, ndatetime;

		isValidDate = false;// 日期是否有效
		isDiscountAmount = false;
		isDiscountPercent = false;
		isMixDiscount = false;

		isLimitQty = false;
		isPackagePrice = false;
		isCurrentPrice = false;
		isHaveSetupDate = false;

		if (getRetailprice() != null) {
			mRetailPrice = Double.valueOf(getRetailprice());
			mRetailQty = (getCurrentqty() == null || getCurrentqty()
					.equals("0")) ? 1 : Integer.valueOf(getCurrentqty());
		}

		if (getPricemm() != null) {
			haveMixAndMatch = true;
			mMixMatch = Integer.valueOf(getPricemm());
		}
		String s = getDiscountamount();
		if (getDiscountamount() != null) {
			isMixDiscount = true;
			isDiscountAmount = true;
			mDiscountAmount = Double.valueOf(getDiscountamount());
		}

		if (getDiscountpercent() != null) {
			isMixDiscount = true;
			isDiscountPercent = true;
			mDiscountPercent = Double.valueOf(getDiscountpercent()) * 0.01;
		}

		// discount link
		if (getDislink() != null) {
			isMixDiscount = true;
			isDiscountLink = true;
			mDisLink = Integer.valueOf(getDislink());
		}

		if (getPrice() != null) {
			isCurrentPrice = true;
			mCurrentPriceQty = (getPriceMultiple() == null || getPriceMultiple()
					.equals("0")) ? 1 : Integer.valueOf(getPriceMultiple());
			mCurrentPrice = Double.valueOf(getPrice());
		}

		if (getPackageprice() != null) {
			isPackagePrice = true;
			mPackageQty = (getPackagepricemultiple() == null || getPackagepricemultiple()
					.equals("0")) ? 1 : Integer
					.valueOf(getPackagepricemultiple());
			mPackagePrice = Double.valueOf(getPackageprice());
		}

		if ((getStartdate() != null) && (getEnddate() != null)) {
			if (!getStartdate().equals("null") && !getStartdate().equals("")
					&& !getEnddate().equals("null") && !getEnddate().equals("")) {
				String ls1 =  getStartdate();
				String ls2 = getStarttime();
				String ls = getStartdate() + getStarttime();
				
				sdatetime = Long.valueOf(getStartdate() + getStarttime())
						.longValue();
				edatetime = Long.valueOf(getEnddate() + getEndtime())
						.longValue();
				ndatetime = Long.valueOf(MoleQUtil.getNow()).longValue();
				if (ndatetime >= sdatetime && ndatetime <= edatetime) {
					isValidDate = true;
				}
				isHaveSetupDate = true;
			}

		}

		if (getLimitedqtyprice() != null
				&& !getLimitedqtyprice().equals("null")) {
			isLimitQty = true;
			mLimitQty = (getLimitedqtyamount() == null || getLimitedqtyamount()
					.equals("0")) ? 1 : Integer.valueOf(getLimitedqtyamount());
			mLimitPrice = Double.valueOf(getLimitedqtyprice());
		}

		if (getPrice_lvl() != null) {
			mPriceLvl = Integer.valueOf(getPrice_lvl());
		}
	}

	public String getDislink() {
		return dislink;
	}

	public void setDislink(String dislink) {
		this.dislink = dislink;
	}

	public String getRetailprice() {
		return retailprice;
	}

	public void setRetailPrice(String price) {
		this.retailprice = price;
	}

	public String getCurrentqty() {
		return currentqty;
	}

	public void setCurrentqty(String currentqty) {
		this.currentqty = currentqty;
	}

	public String getUpc() {
		return upc;
	}

	public void setUpc(String upc) {
		this.upc = upc;
	}

	public String getPriceMultiple() {
		return priceMultiple;
	}

	public void setPriceMultiple(String priceMultiple) {
		this.priceMultiple = priceMultiple;
	}

	public String getPrice() {
		return price;
	}

	public void setPrice(String price) {
		this.price = price;
	}

	public String getStartdate() {
		String result = startdate;
		if(result != null)result = result.replace("'","");
		return result;
	}

	public void setStartdate(String startdate) {
		this.startdate = startdate;
	}

	public String getStarttime() {
		String result = starttime;
		if(result != null)result = result.replace("'","");
		return result;
	}

	public void setStarttime(String starttime) {
		this.starttime = starttime;
	}

	public String getEnddate() {
		String result = enddate;
		if(result != null)result = result.replace("'","");
		return result;
	}

	public void setEnddate(String enddate) {
		this.enddate = enddate;
	}

	public String getEndtime() {
		String result = endtime;
		if(result != null)result = result.replace("'","");
		return result;
	}

	public void setEndtime(String endtime) {
		this.endtime = endtime;
	}

	public String getPackagepricemultiple() {
		return packagepricemultiple;
	}

	public void setPackagepricemultiple(String packagepricemultiple) {
		this.packagepricemultiple = packagepricemultiple;
	}

	public String getPackageprice() {
		return packageprice;
	}

	public void setPackageprice(String packageprice) {
		this.packageprice = packageprice;
	}

	public String getLimitedqtyamount() {
		return limitedqtyamount;
	}

	public void setLimitedqtyamount(String limitedqtyamount) {
		this.limitedqtyamount = limitedqtyamount;
	}

	public String getLimitedqtyprice() {
		return limitedqtyprice;
	}

	public void setLimitedqtyprice(String limitedqtyprice) {
		this.limitedqtyprice = limitedqtyprice;
	}

	public String getDiscountamount() {
		return discountamount;
	}

	public void setDiscountamount(String discountamount) {
		this.discountamount = discountamount;
	}

	public String getDiscountpercent() {
		return discountpercent;
	}

	public void setDiscountpercent(String discountpercent) {
		this.discountpercent = discountpercent;
	}

	public String getPricemm() {
		return pricemm;
	}

	public void setPricemm(String pricemm) {
		this.pricemm = pricemm;
	}

	public String getCreateTime() {
		return createTime;
	}

	public void setCreateTime(String createTime) {
		this.createTime = createTime;
	}

	public String getUpdateTime() {
		return updateTime;
	}

	public void setUpdateTime(String updateTime) {
		this.updateTime = updateTime;
	}

	public String getPrice_lvl() {
		return price_lvl;
	}

	public void setPrice_lvl(String price_lvl) {
		this.price_lvl = price_lvl;
	}

	public String toMGData(String Action) {
		String Result = Action + "|" + DatabaseSchema.PriceSetting.SCHEMA_NAME
				+ "|(" + CheckNull(getUpc()) + "," + CheckNull(getPriceMultiple()) + ","
				+ CheckNull(getPrice()) + "," + CheckNull(getStartdate()) + "," + CheckNull(getStarttime())
				+ "," + CheckNull(getEnddate()) + "," + CheckNull(getEndtime()) + ","
				+ CheckNull(getPackagepricemultiple()) + "," + CheckNull(getPackageprice()) + ","
				+ CheckNull(getLimitedqtyamount()) + "," + CheckNull(getLimitedqtyprice()) + ","
				+ CheckNull(getDiscountamount()) + "," + CheckNull(getDiscountpercent()) + ","
				+ CheckNull(getPricemm()) + "," + CheckNull(getCreateTime()) + ","
				+ CheckNull(getUpdateTime()) + "," + CheckNull(getDislink()) + "," + CheckNull(getPrice_lvl()) + ")";
		return Result;
	}
	
	public String CheckNull(String value) {
		if (value == null) {
			return null;
		} else {
			return "'" + value + "'";
		}
	}

}
